import 'package:flutter/material.dart';
import 'package:wallet_home/page/theme/colors.dart';
import 'package:wallet_home/tools/theme_utils.dart';
import 'package:flutter_lang/flutter_lang.dart';
import 'package:wallet_home/module_config.dart';

class CoinDetailTabWidget extends StatefulWidget
    implements PreferredSizeWidget {
  final TabController controller;
  final ValueChanged<int> onTap;

  CoinDetailTabWidget({@required this.controller, @required this.onTap});

  @override
  _CoinDetailTabState createState() => _CoinDetailTabState();

  @override
  Size get preferredSize => Size.fromHeight(50);
}

class _CoinDetailTabState extends State<CoinDetailTabWidget> {
  @override
  Widget build(BuildContext context) {
    return Container(
        width: double.infinity,
        height: 50,
        color: ThemeUtils.getThemeColor(
            context: context,
            brightnessColor: Colors.white,
            darkColor: Colors.black87),
        child: Stack(
          children: <Widget>[
            Positioned(
              child: Divider(
                color: ThemeUtils.getThemeColor(
                    context: context,
                    brightnessColor: Colors.white,
                    darkColor: Colors.black87),
                height: 2,
                thickness: 1,
              ),
              bottom: 0,
              left: 0,
              right: 0,
            ),
            Container(
              width: double.infinity,
              height: 50,
              child: _orderTabBar(context),
              decoration: BoxDecoration(
                color: Color(0xffffff),
                border: Border(
                    bottom: BorderSide(width: 0.5, color: Color(0xdddddd))),
              ),
            ),
          ],
        ));
  }

  Widget _orderTabBar(BuildContext context) {
//    ThemeUtils.getThemeColor(
//        context: context,
//        brightnessColor: Colours.app_main,
//        darkColor: Colours.color_gold)
    return TabBar(
      isScrollable: true,
      controller: widget.controller,
      indicatorColor: ThemeUtils.getThemeColor(
          context: context,
          brightnessColor: Colours.app_main,
          darkColor: Colours.color_gold),
      labelColor: ThemeUtils.getThemeColor(
          context: context,
          brightnessColor: Colours.app_main,
          darkColor: Colours.color_gold),
      labelStyle: TextStyle(fontSize: 14),
      unselectedLabelColor: ThemeUtils.getThemeColor(
          context: context,
          brightnessColor: Colors.grey[800],
          darkColor: Colors.white60),
      unselectedLabelStyle: TextStyle(fontSize: 14),
      tabs: <Widget>[
        Container(
          alignment: Alignment.center,
          width: 60,
          margin: EdgeInsets.fromLTRB(0, 0, 0, 0),
          child: Text(
            '${WXLang.$t("home_all",package: ModuleConfig.moduleName)}',
          ),
        ),
        Container(
          width: 60,
          alignment: Alignment.center,
          child: Text('${WXLang.$t("home_transfer",package: ModuleConfig.moduleName)}'),
        ),
        Container(
          width: 60,
          alignment: Alignment.center,
          child: Text('${WXLang.$t("home_receive",package: ModuleConfig.moduleName)}'),
        ),
      ],
      onTap: (index) {
        widget.onTap(index);
      },
    );
  }
}
